package com.nwpusp.display.views.components;

import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;

import com.example.petssports.R;
import com.nwpusp.display.GlobalVar;

public class End_Effect1 extends View{
	public Bitmap effect1Bitmap;
	public Bitmap effect2Bitmap;
	public Bitmap effect3Bitmap;
	public Bitmap rtnBitmap;
	public float x;
	public float y;
	public float scale;
	public float width;
	public float height;
	private Timer timer;
	private TimerTask task;
	private int tick = 0;
	
	public End_Effect1(Context view,float scale,int index){
		super(view);
		this.scale = scale;
		this.tick = index;
		getBitmapSource();
		effect1Bitmap = GlobalVar.VerticalScale(effect1Bitmap,scale);
		effect2Bitmap = GlobalVar.VerticalScale(effect2Bitmap,scale);
		effect3Bitmap = GlobalVar.VerticalScale(effect3Bitmap,scale);
		width = effect1Bitmap.getWidth();
		height = effect1Bitmap.getHeight();
		startTimer();
	}
	
	public void setLocation(float x ,float y){
		this.x = x;
		this.y = y;
	}
	
	private void getBitmapSource(){
		effect1Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.end_effect1);
		effect2Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.end_effect2);
		effect3Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.end_effect3);
	}
	
	public void startTimer(){
		timer = new Timer();
		task = getNewTimerTask();
		timer.schedule(task,0, 200);
	}
	
	public void stopTimer(){
		timer.cancel();
	}
	
	 public TimerTask getNewTimerTask(){
		TimerTask task = new TimerTask(){  
			public void run() {
				tick++;
				tick = tick%4;
				switch(tick){
					case 0 : {
						rtnBitmap = effect1Bitmap;
						break;
					}
					case 1 : {
						rtnBitmap = effect2Bitmap;
						break;
					}
					case 2 : {
						rtnBitmap = effect3Bitmap;
						break;
					}
					case 3 : {
						rtnBitmap = effect2Bitmap;
						break;
					}

					default:break;
				}
			}
		};
		return task;
	 }
	
	public Bitmap draw(){
		return rtnBitmap;
	}
	

}
